package com.css.zfzx.fwsjcj.modules.reinforce.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.org.dept.repository.entity.DeptEntity;
import com.css.bpm.platform.org.division.repository.DivisionRepository;
import com.css.bpm.platform.org.division.repository.entity.DivisionEntity;
import com.css.bpm.platform.org.role.repository.entity.RoleEntity;
import com.css.bpm.platform.org.user.repository.entity.UserEntity;
import com.css.bpm.platform.utils.PlatformSessionUtils;
import com.css.bpm.platform.utils.UUIDGenerator;
import com.css.zfzx.fwsjcj.commen.util.Constant;
import com.css.zfzx.fwsjcj.commen.util.EasyPoiExcelUtil;
import com.css.zfzx.fwsjcj.commen.util.ServerUtil;
import com.css.zfzx.fwsjcj.commen.util.SpringUtil;
import com.css.zfzx.fwsjcj.modules.reinforce.entity.FwReinforceEntity;
import com.css.zfzx.fwsjcj.modules.reinforce.entity.QFwReinforceEntity;
import com.css.zfzx.fwsjcj.modules.reinforce.repository.FwReinforceRepository;
import com.css.zfzx.fwsjcj.modules.reinforce.service.FwReinforceService;
import com.css.zfzx.fwsjcj.modules.reinforce.vo.NewProjectVO;
import com.css.zfzx.fwsjcj.modules.reinforce.vo.QueryVO;
import com.css.zfzx.fwsjcj.modules.reinforce.vo.ReinforceVO;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.querydsl.core.types.Predicate;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author leon
 * @Title:
 * @Description:
 * @date 2020/8/26 16:02
 */
@Service
@PropertySource("classpath:platform-config.yml")
public class FwReinforceServiceImpl implements FwReinforceService {

    @Autowired
    private FwReinforceRepository fwReinforceRepository;
    @Autowired
    private JPAQueryFactory jpaQueryFactory;
    /**
     * 图片服务器文件盘符
     **/
    @Value("${image.localDir}")
    private String localDir;
    /**
     * 超级管理员
     */
    @Value("${role.superCode}")
    private String superCode;
    /**
     * 加固工程管理员
     */
    @Value("${role.gcCode}")
    private String gcCode;
    /**
     * 加固工程省级管理员
     */
    @Value("${role.gcProvinceCode}")
    private String gcProvinceCode;

    @Autowired
    private DivisionRepository divisionRepository;

    @Override
    public void save(String type, FwReinforceEntity fwReinforceEntity) {
        String userId = PlatformSessionUtils.getUserId();
        UserEntity user = PlatformAPI.getOrgAPI().getUserAPI().getUser(userId);
        fwReinforceEntity.setId(UUIDGenerator.getUUID());
        // 创建人信息
        fwReinforceEntity.setCreateId(userId);
        fwReinforceEntity.setCreateUser(user.getUserName());
        fwReinforceEntity.setCreateTime(new Date());
        // 状态
        if (StringUtils.isEmpty(type)) {
            throw new RuntimeException("新增审核类型不能为空");
        }
        fwReinforceEntity.setStatus(type);
        // 删除标识
        fwReinforceEntity.setDelFlag(Constant.DEL_NO);

        fwReinforceRepository.save(fwReinforceEntity);

    }

    @Override
    public void update(FwReinforceEntity fwReinforceEntity) {
        if (StringUtils.isEmpty(fwReinforceEntity.getId())) {
            throw new RuntimeException("ID不能为空！");
        }
        FwReinforceEntity targetReinforceEntity = fwReinforceRepository.findById(fwReinforceEntity.getId()).get();
        SpringUtil.copyPropertiesIgnoreEmpty(fwReinforceEntity, targetReinforceEntity);
        fwReinforceRepository.save(targetReinforceEntity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void submit(List<String> ids) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        jpaQueryFactory.update(q)
                .set(q.status, Constant.DAI_SP)
                .where(q.id.in(ids))
                .execute();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<String> ids) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        jpaQueryFactory.update(q)
                .set(q.delFlag, Constant.DEL_YES)
                .where(q.id.in(ids))
                .execute();
    }

    @Override
    public FwReinforceEntity getOne(String id) {
        return fwReinforceRepository.findById(id).get();
    }

    @Override
    public JSONObject getPage(String projectType, String status, int curPage, int pageSize) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        // 只查询当前登录用户信息
        String userId = PlatformSessionUtils.getUserId();
        predicate = ExpressionUtils.and(predicate, q.createId.eq(userId));

        // 工程类别
        predicate = StringUtils.isEmpty(projectType) ? predicate : ExpressionUtils.and(predicate, q.projectType.eq(projectType));
        // 删除标识
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.DEL_NO));
        //审核类别
        predicate = StringUtils.isEmpty(status) ? predicate : ExpressionUtils.and(predicate, q.status.eq(status));
        // 结果
        QueryResults<FwReinforceEntity> page = jpaQueryFactory
                .selectFrom(q)
                .where(predicate)
                .orderBy(q.createTime.desc())
                .offset(curPage - 1)   //起始页
                .limit(pageSize)  //每页大小
                .fetchResults();
        /**
         * 适配base转为JSONObject类型
         */
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", page.getResults());
        jsonObject.put("total", page.getTotal());
        return jsonObject;
    }

    @Override
    public JSONObject getPage(String projectType, QueryVO queryVO, int curPage, int pageSize) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        // 查询条件
        if (queryVO != null) {
            // 工程名称
            String name = queryVO.getName();
            predicate = StringUtils.isEmpty(name) ? predicate : ExpressionUtils.and(predicate, q.name.like("%" + name + "%"));
            // 数据采集人
            String createUser = queryVO.getCreateUser();
            predicate = StringUtils.isEmpty(createUser) ? predicate : ExpressionUtils.and(predicate, q.createUser.like("%" + createUser + "%"));
            // 状态
            String status = queryVO.getStatus();
            predicate = StringUtils.isEmpty(status) ? predicate : ExpressionUtils.and(predicate, q.status.like("%" + status + "%"));
        }
        // 只查询当前登录用户信息
        /*String userId = PlatformSessionUtils.getUserId();
        predicate = ExpressionUtils.and(predicate, q.createId.eq(userId));*/
        // 查询不为未提交状态的
        predicate = ExpressionUtils.and(predicate, q.status.ne(Constant.NO_SUB));
        // 工程类别
        predicate = ExpressionUtils.and(predicate, q.projectType.eq(projectType));
        // 删除标识
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.DEL_NO));
        // 结果
        QueryResults<FwReinforceEntity> page = jpaQueryFactory
                .selectFrom(q)
                .where(predicate)
                .orderBy(q.createTime.desc())
                .offset(curPage - 1)   //起始页
                .limit(pageSize)  //每页大小
                .fetchResults();
        /**
         * 适配base转为JSONObject类型
         */
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", page.getResults());
        jsonObject.put("total", page.getTotal());
        return jsonObject;
    }

    @Override
    public List<FwReinforceEntity> listReinforeByParam(QueryVO queryVO) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        // 查询条件
        if (queryVO != null) {
            // 项目工程类型：0加固工程，1新建工程
            String projectType = queryVO.getProjectType();
            if (StringUtils.isEmpty(projectType)) {
                throw new RuntimeException("工程类别不能为空！");
            } else {
                predicate = ExpressionUtils.and(predicate, q.projectType.eq(projectType));
            }
            // 工程名称
            String name = queryVO.getName();
            predicate = StringUtils.isEmpty(name) ? predicate : ExpressionUtils.and(predicate, q.name.like("%" + name + "%"));
            // 数据采集人
            String createUser = queryVO.getCreateUser();
            predicate = StringUtils.isEmpty(createUser) ? predicate : ExpressionUtils.and(predicate, q.createUser.like("%" + createUser + "%"));
            // 状态
            String status = queryVO.getStatus();
            predicate = StringUtils.isEmpty(status) ? predicate : ExpressionUtils.and(predicate, q.status.like("%" + status + "%"));
        }
        // 只查询当前登录用户信息
        /*String userId = PlatformSessionUtils.getUserId();
        predicate = ExpressionUtils.and(predicate, q.createId.eq(userId));*/
        // 删除标识
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.DEL_NO));
        return jpaQueryFactory
                .selectFrom(q)
                .where(predicate)
                .orderBy(q.createTime.desc())
                .fetch();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void check(List<String> ids, String status, String reason) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        jpaQueryFactory.update(q)
                .set(q.status, status)
                .set(q.reason, reason)
                .where(q.id.in(ids))
                .execute();
    }

    @Override
    public List<FwReinforceEntity> listReinforeByIds(List<String> ids) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        return jpaQueryFactory.selectFrom(q)
                .where(q.id.in(ids))
                .fetch();
    }

    @Override
    public void export(QueryVO queryVO, HttpServletResponse response) {
        List<FwReinforceEntity> fwReinforceEntities = this.listReinforeByParam(queryVO);
        // 前缀
        String prefix = "";
        if ("0".equals(queryVO.getProjectType())) {
            prefix = "加固";
            // 将fwReinforceEntities转换为ReinforceVO
            ArrayList<ReinforceVO> reinforceVOS = ReinforceVO.change2ReinforceVO(fwReinforceEntities);
            // 生成workbook 并导出
            EasyPoiExcelUtil.exportExcel(reinforceVOS, prefix + "工程信息统计", prefix + "工程信息统计", ReinforceVO.class, prefix + "工程信息.xls", response);
        } else {
            prefix = "新建";
            ArrayList<NewProjectVO> newProjectVOS = NewProjectVO.change2ReinforceVO(fwReinforceEntities);
            // 生成workbook 并导出
            EasyPoiExcelUtil.exportExcel(newProjectVOS, prefix + "工程信息统计", prefix + "工程信息统计", NewProjectVO.class, prefix + "工程信息.xls", response);
        }

    }

    @Override
    public Boolean isEmpty(QueryVO queryVO) {
        List<FwReinforceEntity> reinforceEntities = this.listReinforeByParam(queryVO);
        if (reinforceEntities != null) {
            if (reinforceEntities.size() <= 0) {
                return true;
            } else {
                return false;
            }
        }
        return true;
    }

    @Override
    public List<String> listImagesByType(String type) {
        ArrayList<String> imageList = new ArrayList<>();
        QueryVO queryVO = new QueryVO();
        queryVO.setProjectType(type);
        List<FwReinforceEntity> reinforceEntities = this.listReinforeByParam(queryVO);
        for (FwReinforceEntity re : reinforceEntities) {
            String images = re.getPictureCompleteConstruction();
            this.splitImage(images, imageList);
        }
        return imageList;
    }

    @Override
    public List<FwReinforceEntity> findForm() {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        String userId = PlatformSessionUtils.getUserId();
        List<RoleEntity> roles = PlatformAPI.getOrgAPI().getUserAPI().getRoles(userId);
        //是否为超级管理员
        boolean containtRole = ServerUtil.isContaintRole(roles, superCode);
        //是否为加固工程管理员
        boolean containtRoleJG = ServerUtil.isContaintRole(roles, gcCode);
        //是否为加固工程省级管理员
        boolean containtRoleCity = ServerUtil.isContaintRole(roles, gcProvinceCode);
        if (!containtRole && !containtRoleJG) {
            DeptEntity mainDept = PlatformAPI.getOrgAPI().getUserAPI().getMainDept(userId);
            String divisionId = mainDept.getDivisionId();
            DivisionEntity validDivisionById = divisionRepository.findValidDivisionById(divisionId);
            String divisionName = validDivisionById.getDivisionName();
            predicate = ExpressionUtils.and(predicate, q.address.like("%" + divisionName + "%"));
        }
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.DEL_NO));

        return jpaQueryFactory.selectFrom(q).where(predicate).fetch();
    }

    @Override
    public long count(QueryVO queryVO) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        // 查询条件
        if (queryVO != null) {
            // 项目工程类型：0加固工程，1新建工程
            String projectType = queryVO.getProjectType();
            predicate = StringUtils.isEmpty(projectType) ? predicate :
                    ExpressionUtils.and(predicate, q.projectType.eq(projectType));

            // 省
            String province = queryVO.getProvince();
            predicate = StringUtils.isEmpty(province) ? predicate :
                    ExpressionUtils.and(predicate, q.province.like("%" + province + "%"));
            // 市
            String city = queryVO.getCity();
            predicate = StringUtils.isEmpty(city) ? predicate :
                    ExpressionUtils.and(predicate, q.city.like("%" + city + "%"));
            // 区
            String area = queryVO.getArea();
            predicate = StringUtils.isEmpty(area) ? predicate :
                    ExpressionUtils.and(predicate, q.area.like("%" + area + "%"));
            // 采集日期
            String createTime = queryVO.getCreateTime();
            if (StringUtils.isNotBlank(createTime)) {
                // 注意月份是MM
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    String beginDate = createTime + " 00:00:00";
                    String endDate = createTime + " 23:59:59";
                    predicate = ExpressionUtils.and(predicate, q.createTime.between(sdf.parse(beginDate), sdf.parse(endDate)));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            // 工程类别
            String category = queryVO.getCategory();
            predicate = StringUtils.isEmpty(category) ? predicate :
                    ExpressionUtils.and(predicate, q.category.like("%" + category + "%"));

            // 状态(审核通过、未审核) 1待审核，3审核通过
            String status = queryVO.getStatus();
            if ("未审核".equals(status)) {
                status = "1";
            } else if ("审核通过".equals(status)) {
                status = "3";
            }
            predicate = StringUtils.isEmpty(status) ? predicate :
                    ExpressionUtils.and(predicate, q.status.eq(status));
        }
        // 删除标识
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.DEL_NO));
        // 状态 只查询状态为审核通过、未审核
        predicate = ExpressionUtils.and(predicate, q.status.in("1", "3"));

        return jpaQueryFactory.selectFrom(q).where(predicate).fetchCount();
    }

    @Override
    public List<Map> projectPieNumByCategory(QueryVO queryVO) {
        String[] array = new String[]{"城镇住宅", "大中小学校", "医院", "农村民居", "重要交通生命线",
                "电力网络", "电信网络", "水库大坝", "危险化学品厂库", "应急避难场所建设"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String category : array) {
            // 结构类型查询参数变化
            queryVO.setCategory(category);
            Long count = 0L;
            // 工程类别数量
            count = count(queryVO);
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", category);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<FwReinforceEntity> findVialdForm(QueryVO queryVO) {
        QFwReinforceEntity q = QFwReinforceEntity.fwReinforceEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        // 查询条件
        if (queryVO != null) {
            // 项目工程类型：0加固工程，1新建工程
            String projectType = queryVO.getProjectType();
            if (!StringUtils.isEmpty(projectType)) {
                predicate = ExpressionUtils.and(predicate, q.projectType.eq(projectType));
            }
            // 省
            String province = queryVO.getProvince();
            predicate = StringUtils.isEmpty(province) ? predicate :
                    ExpressionUtils.and(predicate, q.province.like("%" + province + "%"));
            // 市
            String city = queryVO.getCity();
            predicate = StringUtils.isEmpty(city) ? predicate :
                    ExpressionUtils.and(predicate, q.city.like("%" + city + "%"));
            // 区
            String area = queryVO.getArea();
            predicate = StringUtils.isEmpty(area) ? predicate :
                    ExpressionUtils.and(predicate, q.area.like("%" + area + "%"));
            // 状态(审核通过、未审核)
            String status = queryVO.getStatus();
            if(StringUtils.isNotEmpty(status)) {
                if ("审核通过".equals(queryVO.getStatus())) {
                    predicate = ExpressionUtils.and(predicate, q.status.eq("1"));
                } else if("未审核".equals(status)){
                    predicate = ExpressionUtils.and(predicate, q.status.eq("3"));
                }
            }
        }
        // 删除标识
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.DEL_NO));

        predicate=ExpressionUtils.and(predicate,q.status.in("1","3"));

        return jpaQueryFactory.selectFrom(q).where(predicate).fetch();
    }

    @Override
    public List<Map> findBarByYear(QueryVO queryVO) {
        String[] array = new String[]{"80s以前", "80s-90s", "90s-00s", "00s-10s", "10s以后", "建设中（新增）"};
        //80s以前
        List<FwReinforceEntity> entityList80s = new ArrayList<>();
        //80s-90s
        List<FwReinforceEntity> entityList80s90s = new ArrayList<>();
        //90s-00s
        List<FwReinforceEntity> entityList90s00s = new ArrayList<>();
        //00s-10s
        List<FwReinforceEntity> entityList00s10s = new ArrayList<>();
        //10s以后
        List<FwReinforceEntity> entityList10s = new ArrayList<>();
        //加固工程
        queryVO.setProjectType("0");
        List<FwReinforceEntity> vialdForm = findVialdForm(queryVO);
        for (FwReinforceEntity fwRen : vialdForm) {
            String reinforceTime = fwRen.getReinforceTime();
            if (StringUtils.isNotEmpty(reinforceTime)) {
                String year = reinforceTime.split("-")[0];
                if (Integer.valueOf(year) < 1980) {
                    entityList80s.add(fwRen);
                }
                if (1980 <= Integer.valueOf(year) && Integer.valueOf(year) < 1990) {
                    entityList80s90s.add(fwRen);
                }
                if (1990 <= Integer.valueOf(year) && Integer.valueOf(year) < 2000) {
                    entityList90s00s.add(fwRen);
                }
                if (2000 <= Integer.valueOf(year) && Integer.valueOf(year) < 2010) {
                    entityList00s10s.add(fwRen);
                }
                if (2010 <= Integer.valueOf(year)) {
                    entityList10s.add(fwRen);
                }
            } else {
                continue;
            }
        }
        //新建工程
        queryVO.setProjectType("1");
        List<FwReinforceEntity> newReinforce = findVialdForm(queryVO);
        //返回数值
        List<Map> arrayList = new ArrayList<>();
        for (String arr : array) {
            Map map = new HashMap();
            if (arr.equals("80s以前")) {
                map.put("name", arr);
                map.put("value", entityList80s.size());
                arrayList.add(map);
            }
            if (arr.equals("80s-90s")) {
                map.put("name", arr);
                map.put("value", entityList80s90s.size());
                arrayList.add(map);
            }
            if (arr.equals("90s-00s")) {
                map.put("name", arr);
                map.put("value", entityList90s00s.size());
                arrayList.add(map);
            }
            if (arr.equals("00s-10s")) {
                map.put("name", arr);
                map.put("value", entityList00s10s.size());
                arrayList.add(map);
            }
            if (arr.equals("10s以后")){
                map.put("name",arr);
                map.put("value",entityList10s.size());
                arrayList.add(map);
            }
            if (arr.equals("建设中（新增）")) {
                map.put("name", arr);
                map.put("value", newReinforce.size());
                arrayList.add(map);
            }
        }
        return arrayList;
    }

    @Override
    public List<HashMap> listProvices(QueryVO queryVO) {
        // 31个省
        List<DivisionEntity> subDivisions = PlatformAPI.getDivisionAPI().getSubDivisions("root");
        ArrayList<HashMap> maps = new ArrayList<>();
        for (DivisionEntity division : subDivisions) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("provice", division.getDivisionName());
            // 查询单个省的数据
            queryVO.setProvince(division.getDivisionName());

            // 加固工程
            queryVO.setProjectType("0");
            long reinforeCount = count(queryVO);
            map.put("reinforeCount", reinforeCount);

            // 新建工程
            queryVO.setProjectType("1");
            long newCount = count(queryVO);
            map.put("newCount", newCount);

            maps.add(map);
        }
        return maps;
    }

    @Override
    public List<HashMap> listCities(QueryVO queryVO) {
        // 省或者直辖市名称
        String provice = queryVO.getProvince();
        // 省或者直辖市ID
        String divisionId = queryVO.getDivisionId();
        // 省、直辖市的名称和ID不能为空！
        if (StringUtils.isEmpty(provice) || StringUtils.isEmpty(divisionId)) {
            throw new RuntimeException("省、直辖市的名称和ID不能为空！");
        }
        // 获取省下面的市或者直辖市下面的区
        List<DivisionEntity> subDivisions = PlatformAPI.getDivisionAPI().getSubDivisions(divisionId);
        ArrayList<HashMap> maps = new ArrayList<>();
        for (DivisionEntity division : subDivisions) {
            HashMap<String, Object> map = new HashMap<>();
            // 省
            map.put("provice", provice);

            // 查询单个省(或者直辖市)的数据
            if (provice.equals("北京市") || provice.equals("天津市") ||
                    provice.equals("上海市") || provice.equals("重庆市")) {
                // 若是直辖市则查询区
                queryVO.setArea(division.getDivisionName());
            } else {
                // 非直辖市查询市
                queryVO.setCity(division.getDivisionName());
            }
            // 市
            map.put("city", division.getDivisionName());

            // 加固工程
            queryVO.setProjectType("0");
            long reinforeCount = count(queryVO);
            map.put("reinforeCount", reinforeCount);

            // 新建工程
            queryVO.setProjectType("1");
            long newCount = count(queryVO);
            map.put("newCount", newCount);

            maps.add(map);
        }
        return maps;
    }

    @Override
    public List<HashMap> listAreas(QueryVO queryVO) {
        // 省或者直辖市名称
        String provice = queryVO.getProvince();
        // 市
        String city = queryVO.getCity();
        // 市ID
        String divisionId = queryVO.getDivisionId();
        // 市的名称和ID不能为空！
        if (StringUtils.isEmpty(provice) || StringUtils.isEmpty(divisionId)) {
            throw new RuntimeException("市的名称和ID不能为空！");
        }
        // 获取省下面的市或者直辖市下面的区
        List<DivisionEntity> subDivisions = PlatformAPI.getDivisionAPI().getSubDivisions(divisionId);
        ArrayList<HashMap> maps = new ArrayList<>();
        for (DivisionEntity division : subDivisions) {
            HashMap<String, Object> map = new HashMap<>();
            // 省
            map.put("provice", provice);
            // 市
            map.put("city", city);

            // 查询区
            queryVO.setArea(division.getDivisionName());

            // 区
            map.put("area", division.getDivisionName());

            // 加固工程
            queryVO.setProjectType("0");
            long reinforeCount = count(queryVO);
            map.put("reinforeCount", reinforeCount);

            // 新建工程
            queryVO.setProjectType("1");
            long newCount = count(queryVO);
            map.put("newCount", newCount);

            maps.add(map);
        }
        return maps;
    }

    /**
     * 对图片URL进行切割后放入list
     *
     * @param images
     * @param imageList
     */
    private void splitImage(String images, ArrayList<String> imageList) {
        if (StringUtils.isNotBlank(images)) {
            String[] imageSplit = images.split(",");
            for (String str : imageSplit) {
                int i = str.lastIndexOf("/");
                // 不包含/,如: "1.pnag"
                String substr = str.substring(i + 1);
                imageList.add(localDir + substr);
            }
        }
    }

}
